package cn.alone.basic.service.impl;

import cn.alone.basic.mapper.BaseMapper;
import cn.alone.basic.query.BaseQuery;
import cn.alone.basic.service.IBaseService;
import cn.alone.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    public void delete(Long id) {
        mapper.remove(id);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public T loadById(Long id) {
        return mapper.queryById(id);
    }

    @Override
    public List<T> loadAll() {
        return mapper.queryAll();
    }

    @Override
    public PageList<T> querpage(BaseQuery query) {
        //查询数据总条数
        Long total = mapper.queryCount(query);
        //查询当前页数据
        List<T> rows = mapper.queryData(query);
        //把查询到的数据返回给前端
        return new PageList<T>(total,rows);

    }
}
